package com.lvxtech.gateway;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import com.lvxtech.gateway.service.RouteService;

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication implements CommandLineRunner {
	
	private static final Log log = LogFactory.getLog(GatewayApplication.class);

    public static void main(String[] args) {
        SpringApplication.run( GatewayApplication.class, args );
    }
    
    @Autowired
    RouteService routeService;

	@Override
	public void run(String... args) throws Exception {
		Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() {
			@Override
			public void run() {
				try {
					routeService.loadRouteDefinition();
				} catch (Exception e) {
					log.error("路由信息同步失败",e);
				}
			} 
		}, 0, 1, TimeUnit.MINUTES);
	}
   
}
